package cn.chinaunicom.sdsi.frm.workflow.sample.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.chinaunicom.sdsi.frm.workflow.sample.service.ActTestService;

/**
 * 普通业务推进rest调用示例
 * 
 * @author liyh
 *
 */
@RestController("workflowTestController")
@RequestMapping(value = "/workflowtest")
public class WorkflowTestController {

	/**
	 * 工作流任务相关的业务逻辑组件
	 */
	private ActTestService actTestService;

	@RequestMapping(value = "/startprocess/{processDefinitionKey}/{assignee}", method = RequestMethod.GET)
	public void startProcess(@PathVariable("processDefinitionKey") String processDefinitionKey,
			@PathVariable("assignee") String assignee) {
		actTestService.startProcess(processDefinitionKey, assignee, null);
	}

	@RequestMapping(value = "/startprocess/{processDefinitionKey}/{assignee}/target/{taskDefinitionKey}", method = RequestMethod.GET)
	public void startProcess(@PathVariable("processDefinitionKey") String processDefinitionKey,
			@PathVariable("assignee") String assignee, @PathVariable("taskDefinitionKey") String taskDefinitionKey) {
		actTestService.startProcess(processDefinitionKey, assignee, taskDefinitionKey);
	}

	@RequestMapping(value = "/pushprocess/{processInstanceId}/{taskId}", method = RequestMethod.GET)
	public void pushProcess(@PathVariable("processInstanceId") String processInstanceId,
			@PathVariable("taskId") String taskId) {

		actTestService.pushProcess(processInstanceId, taskId, null, "10001", 1, 0, "浏览器推进测试");
	}

	@RequestMapping(value = "/pushprocess/{processInstanceId}/{taskId}/target/{taskDefinitionKey}", method = RequestMethod.GET)
	public void pushProcess(@PathVariable("processInstanceId") String processInstanceId,
			@PathVariable("taskId") String taskId, @PathVariable("taskDefinitionKey") String taskDefinitionKey) {

		actTestService.pushProcess(processInstanceId, taskId, taskDefinitionKey, "10001", 2, 0, "浏览器推进测试");
	}

	@RequestMapping(value = "/breakprocess/{processInstanceId}/{taskId}", method = RequestMethod.GET)
	public void breakProcess(@PathVariable("processInstanceId") String processInstanceId,
			@PathVariable("taskId") String taskId) {
		actTestService.breakProcess(processInstanceId, taskId, "Rest API 测试调用。");
	}

	@RequestMapping(value = "/withdrawprocess/{processInstanceId}/{taskId}", method = RequestMethod.GET)
	public void withdrawProcess(@PathVariable("processInstanceId") String processInstanceId,
			@PathVariable("taskId") String taskId) {
		actTestService.withdrawProcess(processInstanceId, taskId);
	}

	@Autowired
	public void setActTestService(@Qualifier("actTestService") ActTestService actTestService) {
		this.actTestService = actTestService;
	}

}
